{include file="public/header"}
<title>订单录入</title>
</head>
<body>
<style>
    .col-sm-1 {
        width: 20%;
    !important;
    }
</style>

<article class="page-container">
    <form action="" method="post" class="form form-horizontal" id="form-member-add">

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-1">产品分类：</label>
            <div >
                <select style="width: 30%;margin-left: 2%;display: inline-block" class="chan form-control" name="chan">
                    <option selected="selected">请选择问题</option>
                    <option value="0">套餐</option>
                    <option value="1">维修与安装</option>
                    <option value="2">其他</option>
                </select>&nbsp
            </div>
        </div>
        <div class="row cl cp">

        </div>
        <div class="row cl ll" style="margin-top: 7px;">
            <label class="form-label col-xs-4 col-sm-1">单价：</label>
            <div class="input-group" style="width: 26%;margin-left: 22%;">
                <span class="input-group-addon">$</span>
                <input type="text" class="form-control dan1" name="un_Price" readonly="readonly"
                       style=" background-color: rgb(235, 235, 228); ">


            </div>

        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-1">方量：</label>

                <input type="text" name="square" class="form-control fang"
                       style="display: inline-block;width: 12%;margin-left: 16px;">&nbsp;

                <input type="text" readonly="readonly" name="company" class="companys form-control"
                       style="background-color: rgb(235, 235, 228);display: inline-block;width: 7%;border-left: none;margin-left: -3%;border-left: 1px #ccc solid">
                <span class="input-group-addon" style="    display: inline-block;width: 7%;height: 34px;margin-left: -2%;border-left: 1px #ccc solid;padding-top: 9px"> /单位</span>

        </div>


        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-1">质保：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="radio" value="0" name="zhi" class="zhi" checked="checked">否 &nbsp;&nbsp;&nbsp;&nbsp;
                <input type="radio" value="1" name="zhi" class="zhi">是
            </div>
        </div>
        <div class="row cl" style="display: none">
            <label class="form-label col-xs-4 col-sm-1">价格规则：</label>
            <div class="formControls col-xs-8 col-sm-9">

                <textarea id="price_rule" readonly="readonly" class="form-control"
                          style="width: 481px;margin:0;height: 152px;background-color: rgb(235, 235, 228);"
                          name="rule"></textarea>


            </div>
        </div>
        <input class="order_id" type="hidden" name='order_id' value="{$data.order_id}">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-1">总价：</label>
            <div class="input-group" style="width: 26%;margin-left: 22%;">
                <span class="input-group-addon">$</span>
                <input type="text" class="jia form-control"  name="to_prices" readonly="readonly" style="display: inline-block;">

                <span class="input-group-addon">.00</span>
            </div>
            <input type="hidden" class="jias form-control"  name="to_price" >
        </div>

        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                <button class="btn btn-primary radius" type="button" style="    margin-left: 220px"><i
                        class="Hui-iconfont">&#xe632;</i> 提交
                </button>

            </div>
        </div>

    </form>
</article>
{include file="public/footer"}
<script>
    $('.chan').bind("change", function () {
        $('.shan').remove();
        var cha = $(".chan option:selected").val();
        if (cha == 0) {
          console.log(11);

            var html =
                ' <div class="formControls col-xs-8 col-sm-9 shan" style="margin-left: 28px">' +
                ' <input type="hidden" name="qi_rmakes" value="">' +
                '<label class="form-label col-xs-4 col-sm-1">套餐选择：</label>' +
                '<select style="width: 20%;padding: 0.4%;margin-left: 16px;display: inline-block" name="class_a" class="class_a2 form-control">' +
                '<option selected="selected" value="">请选择</option>' +
                '{volist name="gs" id="v"}' +
                '<option value="{$v.product_id}">{$v.product_title}</option>\n' +
                '{/volist}</select>' +
                '<select style="width: 41%;padding: 0.4%;display: inline-block"  name="class_b" class="class_b form-control">' +
                '<option selected="selected">请选择问题</option>' +
                '</select></div>';

            $(".cp").append(html);
            $('.ll').css('display','block');

        } else if (cha == 1) {


            var html = ' <div class="formControls col-xs-8 col-sm-9 shan" style="margin-bottom: 18px;margin-left: -2%;width: 100%">' +
                ' <input type="hidden" name="qi_rmakes" value="">' +
                '<label class="form-label col-xs-4 col-sm-1">清单选择：</label>' +
                '<select style="width: 20%;padding: 0.4%;margin-left: 16px;display: inline-block"  name="class_a" class="class_a1 form-control">' +
                '<option selected="selected" value="">请选择</option>' +
                '{volist name="po" id="v"}' +
                '<option value="{$v.detailed_id}">{$v.detailed_title}</option>\n' +
                '{/volist}</select>' +
                '<select style="width: 45%;padding: 0.4%;display: inline-block"  name="class_b" class="class_b1 form-control">' +
                '<option selected="selected">请选择</option>' +
                '</select></div>';

            $(".cp").append(html);
            $('.ll').css('display','block');
        } else if (cha == 2) {
            var html = ' <div class="formControls col-xs-8 col-sm-9 shan" style="width: 100%;">' +
                '<label class="form-label col-xs-4 col-sm-1">标题：</label>' +
                '<input type="text" name="class_a" placeholder="请输入标题" style="width:20%" class=" form-control"><br>' +
                '<label class="form-label col-xs-4 col-sm-1" style="">单位：</label>' +
                '<select style="width: 20%;padding: 0.4%;display: inline-block"  name="companys" class="class_a3 form-control">' +
                '<option selected="selected" name="company">请选择</option>' +
                '{volist name="g" id="v"}' +
                '<option value="{$v.title}">{$v.title}</option>\n' +
                '{/volist}</select><br>' +
                '<label class="form-label col-xs-4 col-sm-1" style="margin-top: 11px">标价：</label>' +
                '<input type="number" name="un_Prices" placeholder="请输入标价" style="margin-top: 11px;display: inline-block;width: 20%" class="un_Price form-control"> <br>' +
                '<label class="form-label col-xs-4 col-sm-1" style="text-align: right;    margin-left: -20%;">备注：</label>' +
                ' <textarea style="width: 390px;margin-left: 20%;height: 184px;margin-top: 12px;display: inline-block" name="qi_rmakes" class="form-control"></textarea></div>';
            $(".cp").append(html);
            $('.ll').css('display','none');
            $('.o').remove();
            $('#price_rule').html('');
            $('.fang').val('');
            $('.jias').val('');
            $('.jia').val('');
        }

    });
    $(document).on("change", ".class_a1", function () {
        var detaileds_id = $(this).val();
        console.log(detaileds_id);
        $.post("{:url('index/order/detailed')}", {detaileds_id: detaileds_id}, function (data, textStatus, xhr) {
            var html;
            var artificial;
            var dan;
            var pris;
            if (data.length > 0) {
                for (var i = 0; i < data.length; i++) {
                    html += "<option value='" + data[i]['detailed_id'] + "' >" + data[i]['detailed_title'] + "</option>";
                    artificial = data[0]['artificial'];
                    dan = data[0]['titles'];
                    pris = data[0]['rmakes'];
                }
            } else {
                html += "<option value=''>暂无数据</option>";
            }
            $('.class_b1').html(html);
            $('.dan1').val(artificial);
            $('.companys').val(dan);
            $('#price_rule').html(pris);
            $('.fang').val('');
            $('.jias').val('');
            $('.jia').val('');


        });
    });
    $(document).on("change", ".class_a2", function () {
        var product_id = $(this).val();
        console.log(product_id);
        $.post("{:url('index/order/product_chan')}", {product_id: product_id}, function (data, textStatus, xhr) {
            var html;
            var artificial;
            var dan;
            var price_rule;
            if (data.length > 0) {
                for (var i = 0; i < data.length; i++) {
                    html += "<option value='" + data[i]['product_id'] + "' >" + data[i]['product_title'] + "</option>";
                    artificial = data[0]['prices'];
                    price_rule = data[0]['price_rules'];
                    dan = data[0]['titles'];
                }

            } else {
                html += "<option value=''>暂无数据</option>";

            }
            $('.companys').val(dan);
            $('.class_b').html(html);
            $('.dan1').val(artificial);
            $('#price_rule').html(price_rule);
            $('.fang').val('');
            $('.jias').val('');
            $('.jia').val('');


        });


    });
    $(document).on("change", ".class_b", function () {
        var product_id = $(this).val();
        console.log(product_id);
        $.post("{:url('index/order/product_chan_dan')}", {product_id: product_id}, function (data, textStatus, xhr) {
            var artificial;
            var dan;
            var price_rule;
            artificial = data['prices'];
            dan = data['titles'];
            price_rule = data['price_rules'];
            $('.companys').val(dan);
            $('#price_rule').html(price_rule);

            $('.dan1').val(artificial);
            $('.fang').val('');
            $('.jias').val('');
            $('.jia').val('');


        });


    });
    $(document).on("change", ".class_b1", function () {
        var product_id = $(this).val();
        console.log(product_id);
        $.post("{:url('index/order/detailed_dan')}", {detaileds_id: product_id}, function (data, textStatus, xhr) {
            var artificial;
            var dan;
            var pris;
            artificial = data['artificial'];
            dan = data['titles'];
            pris = data['rmakes'];
            $('#price_rule').html(pris);
            $('.companys').val(dan);
            $('.dan1').val(artificial);
            $('.fang').val('');
            $('.jias').val('');
            $('.jia').val('');


        });


    });
    $(document).on("change", ".un_Price", function () {
        $('.fang').val('');
        $('.jias').val('');
        $('.jia').val('');

    });
    $('.fang').bind("change", function () {

        //向input输入框中赋值
        var chan = $('.chan').val();
        var companys = $('.dan1').val();
        var fang = $('.fang').val();
        if (chan == 2) {
            var un_Price = $('.un_Price').val();
            $('.jia').val((((un_Price * 1000) * fang) / 1000).toFixed(2) );
            $('.jias').val((((un_Price * 1000) * fang) / 1000).toFixed(2));
        } else {
            $('.jia').val((((companys * 1000) * fang) / 1000).toFixed(2));
            $('.jias').val((((companys * 1000) * fang) / 1000).toFixed(2));
        }


    });


    /***
     *
     *
     * 提交代码
     * */
    $('.radius').click(function () {
        var src = "{:Url('index/order/yuan')}";
        $.ajax({
            type: 'POST',
            url: src,
            dataType: 'json',
            data: $('form').serializeArray(),
            success: function (data) {
                var res = JSON.parse(data);
                if (res.code == 200) {
                    layer.msg(res.msg, {icon: 1, time: 2000}, function (index, layero) {
                        setTimeout("window.parent.location.reload()", 1);

                    });
                } else {
                    layer.msg(res.msg, {icon: 5, time: 1000});
                }

            },
            error: function (data) {
                console.log(data.msg);
            },
        });

    });

    /**
     * 赠送项目
     *
     **/
    $(".give_a").bind("change", function () {
        give_b();
    });

    function give_b() //市
    {
        var parent_ids = $(".give_a").find("option:selected").val(); //省id
        console.log(parent_ids);
        $.post("{:url('index/order/detailed')}", {detaileds_id: parent_ids}, function (data, textStatus, xhr) {
            var html;
            if (data.length > 0) {
                for (var i = 0; i < data.length; i++) {
                    html += "<option value='" + data[i]['detailed_id'] + "'>" + data[i]['detailed_title'] + "</option>";
                }

            } else {
                html += "<option value=''>暂无数据</option>";
            }
            $('.give_b').html(html);
        });
    }







</script>
</body>
</html>